﻿<div class="easyui-layout" data-options="fit: true">
    <div data-options="region:'north',border: false,split:true" style="height:50px;">
        <div class="data-tools clearfix">
            <div class="pull-left form-inline ">
            </div>
            <div class="pull-right">
                <form class="form-inline" id="searchForm">
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">排：</label>
                        <input class="form-control wd75" name="pai" type="text" autocomplete="off">
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">列：</label>
                        <input class="form-control wd75" name="lie" type="text" autocomplete="off">
                    </div>
                    <div class="input-group input-group-sm">
                        <label class="input-group-addon m5_l">层：</label>
                        <input class="form-control wd75" name="ceng" type="text" autocomplete="off">
                    </div>
                    <button type="button" class="btn btn-default btn-sm active search m5_r"><span class="glyphicon glyphicon-search"></span> 搜索</button>
                </form>
            </div>
        </div>
    </div>
    <div data-options="region: 'center',  border: false">
        <table id="warehouseUnitDG"></table>
    </div>
</div>
@section footerScript{
    <script type="text/javascript">
        //定义datagrid
        var warehouseUnitDG = $("#warehouseUnitDG");

        $(function () {

            //搜索
            $(".search").click(function () {
                //表单
                var searchform = $("#searchForm").serializeArray();
                //表单转为Json
                var queryParams = warehouseUnit.getJson(searchform);

                warehouseUnitDG.datagrid({
                    queryParams: queryParams
                });

                return false;
            });

            //表单
            var searchform = $("#searchForm").serializeArray();
            //表单转为Json
            var queryParams = warehouseUnit.getJson(searchform);

            Topro.UI.DataGrid(warehouseUnitDG, {
                fit: true,
                method: "get",
                url: "@Url.Action("WarehouseUnitQuery", "Module")",
                queryParams: queryParams,
                idField: 'id',
                remoteSort: false,
                multiSort: false,
                pagination: false,
                singleSelect: true, //是否支持单选
                rownumbers: true,   //行号
                frozenColumns: [
                    [
                        { field: 'ck', checkbox: true }
                    ]
                ],
                columns: [
                    [
                        {
                            field: 'id',
                            title: '编号',
                            width: 100,
                            align: 'center'
                        },
                        {
                            field: '库位',
                            title: '条码',
                            width: 200,
                            formatter: function(value, row, index) {
                                return "{0}-{1}-{2}-{3}".format(row.pai, row.lie, row.ceng,row.fix);
                            }
                        },
                        {
                            field: 'pai',
                            title: '排',
                            width: 75,
                            align: 'center'
                        },
                        {
                            field: 'lie',
                            title: '列',
                            width: 75,
                            align: 'center'
                        },
                        {
                            field: 'ceng',
                            title: '层',
                            width: 75,
                            align: 'center'
                        },
                        {
                            field: 'fix',
                            title: '位置',
                            width: 75,
                            align: 'center'
                        },
                        {
                            field: 'remark',
                            title: '备注',
                            width: 200,
                            align: 'left',
                            formatter: function(value, row, index) {
                                return "";
                            }
                        }
                    ]
                ],
                rowTooltip: false
            });
        });

        var warehouseUnit = {
            getJson: function (array) {
                if (array != undefined && array.length > 0) {
                    var json = {};
                    $(array).each(function (i, v) {
                        json[v.name] = v.value;
                    });
                    return json;
                } else {
                    return {};
                }
            }
        }

        function Tip_success(word) {
            Topro.UI.Tip_success(word);
        }

        function save() {

            var row = warehouseUnitDG.datagrid('getSelected')

            if (Topro.Util.isNullOrEmptySpance(row)) {
                Topro.UI.Tip_danger("请选择库位.")
                return false;
            }

            Topro.UI.DialogOpener().set({
                warehouseUnitId: row.id,
                warehouseUnitCode: "{0}-{1}-{2}-{3}".format(row.pai, row.lie, row.ceng, row.fix)
            });
            Topro.UI.CloseDialog();
        }
    </script>
}

